﻿var pwsmanage = {
    init: function () {
        var _html = [];
        _html.push('<div id="tt" class="easyui-tabs" data-options="fit:\'true\'" >');
        _html.push('<div title=' + lang.basic_information + ' id="t1" data-options="fit:\'true\'" >');
        _html.push('<div id="userinfo_1" style="padding:10px;" class="tablelist">');
        _html.push('</div></div>');
        _html.push('</div>');
        $('body').html(_html.join(''));
        $('body').addClass('easyui-layout');
        $.parser.parse();

        bindUserInfo();
    }
};

//#region 用户信息
var _userinfodata;
function bindUserInfo() {
    var _html = [];
    _html.push('<table  style="width:100%;">');
    _html.push('<tr><td class="tb_title" style="text-align:right;">' + lang.old_password + '：</td><td><input type="password" id="origin_pwd" style="width:240px;"></input><span style="color:red;">*</span></td></tr>');
    _html.push('<tr><td class="tb_title"  style="text-align:right;">' + lang.new_password + '：</td><td><input type="password" id="new_pwd" style="width:240px;"></input><span style="color:red;">*</span></td></tr>');
    _html.push('<tr><td class="tb_title"  style="text-align:right;">' + lang.confirm_password + '：</td><td><input type="password" id="confirm_pwd" style="width:240px;"></input><span style="color:red;">*</span></td></tr>');

    _html.push('<tr id="saveuserinfo" ><td colspan="2" align="center"><span id="saveinfo" style="padding:4px 10px;cursor:pointer;border:1px solid #ccc;background:#f0f0f0;">' + lang.save + '</span><span style="padding:4px 10px;"> </span><span id="cancleinfo" style="padding:4px 10px;cursor:pointer;border:1px solid #ccc;background:#f0f0f0;">' + lang.cancel + '</span></td></tr>');
    _html.push('</table>');
    _html.push('<div style="height:1px;clear:both;"></div>');
    $('#userinfo_1').html(_html.join(''));
    $('#saveinfo').bind('click', function () { saveinfo(); });
    $('#cancleinfo').bind('click', function () {location.reload(); });



}

function saveinfo() {
    if ($('#origin_pwd').val() == '') { alert(lang.The_old_password_cannot_be_empty); return; }
    else if ($('#new_pwd').val() == '') { alert(lang.The_login_password_cannot_be_empty); return; }
    else if ($('#confirm_pwd').val() == '') { alert(lang.The_confirm_password_cannot_be_empty); return; }
    else if ($('#confirm_pwd').val() != $('#new_pwd').val()) { alert(lang.The_two_password_do_not_match_please_input_again); return; }
    //先验证原始密码
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "verifyPassword",
        model: function () {
            var obj = {};
            obj.USER_PWD = hex_md5($('#origin_pwd').val());
            return $.toJSON(obj);
        },
        success: function (data) {
            if (data == true) {
                $.ajaxHandler({
                    url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
                    urlType: "EditStaffUserInfo",
                    model: function () {
                        var obj = {};
                        obj.USER_PWD = hex_md5($('#new_pwd').val());
                        return $.toJSON(obj);
                    },
                    success: function (data) {
                        alert(lang.Password_updated_successfully);
                        location.reload();
                    }
                });
            }
            else {
                alert(lang.The_old_password_is_wrong);
            }
        }

    });
    //    $.ajaxHandler({
    //        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
    //        urlType: "EditStaffUserInfo",
    //        model: function () {
    //            var obj = {};
    //            obj.USER_PWD = hex_md5($('#new_pwd').val());
    //            return $.toJSON(obj);
    //        },
    //        success: function (data) {
    //            alert(lang.Password_updated_successfully);
    //            location.reload();
    //        }
    //    });

}
//#endregion


